<template>
    <ListPage ref="page" :query="query" :api="getRenewManageList">

        <template #search="{ page, hiddenColumns }">
            <PageSearch ref="search" :query="query" :page="page" has-box @search="() => ($refs.page as any).getData()">
                <template #auth>
                </template>
                <template #input="{ }">
                    <SearchInput v-model="query.keyword" placeholder="客户名称/店铺名称" :data="query"
                        :hidden-columns="(hiddenColumns as any)" @trigger="(e) => ($refs.search as any).trigger(e)"
                        @search="() => ($refs.page as any).getData()"
                        @change-column="(prop) => ($refs.page as any).changeColumn(prop)"></SearchInput>
                </template>
            </PageSearch>
        </template>

        <template #table="{ data, hiddenColumns }">
            <ListTable :data="data" :hidden-columns="(hiddenColumns as any)" @open-sk="openSk" @open-tk="openTk"
                @open-xf="openXf">
            </ListTable>
        </template>

        <template #pagination="{ page, total }">
            <PagePagination :page="page" :total="total" @changePage="(v) => ($refs.page as any).changePage(v)">
            </PagePagination>
        </template>
    </ListPage>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import ListPage from '@/components/list-page/ListPage.vue'
import { getRenewManageList } from '../api'
import ListTable from './ListTable.vue'
import PageSearch from '@/components/list-page/PageSearch.vue'
import SearchInput from '@/components/list-page/SearchInput.vue'
import { useAuth } from '@/utils/auth'
import { addSkDialog, addTkDialog, addXfDialog } from '../dialog/sktk'
import PagePagination from '@/components/list-page/PagePagination.vue'
import { ElMessage } from 'element-plus'

const page = ref()

const query = reactive({
    keyword: ''
})

const auth = useAuth()

const openSk = async (row) => {
    if(row.xfztVal === '续费成功'){
        ElMessage.warning('无法收款,订单已完成续费!')
        return;
    }

    if(row.xfztVal === '无效'){
        ElMessage.warning('无效订单无法收款!')
        return;
    }

    await addSkDialog.open({ row });
    page.value && page.value.getData();
}

const openTk = async (row) => {
    if (row.zfztVal == '待支付') {
        ElMessage.warning('无法退款,该订单尚未支付!');
        return;
    }

    if(row.xfztVal === '续费成功'){
        ElMessage.warning('无法退款,订单已完成续费!')
        return;
    }

    if(row.xfztVal === '无效'){
        ElMessage.warning('无效订单无法退款!')
        return;
    }

    await addTkDialog.open({ row });
    page.value && page.value.getData();
}

const openXf = async (row) => {
    /*
    if (row.ddztVal == '续费失败' || row.sfmsVal == '无需收费') {
        ElMessage.warning('续费失败,请确认该业务是否已停止合作!')
        return;
    }
    */

    if(row.xfztVal === '无效'){
        ElMessage.warning('无效订单无法续费!')
        return;
    }

    // if(row.xfztVal === '续费成功'){
    //     ElMessage.warning('订单已续费!')
    //     return;
    // }
    await addXfDialog.open({ row })
    page.value && page.value.getData();
}
</script>